<!--每月考勤报表明细-->
<template>
  <div class="app-container" style="background-color:#F8F8F8">

    <div slot="header" style="margin:16px 0">
      <span>考勤日期:{{ workTime }}    考勤组：{{ deptName }}</span>
    </div>
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true" @submit.native.prevent>
      <el-form-item label="岗位" prop="postName">
        <el-input
          v-model="queryParams.postName"
          placeholder="请输入岗位"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="姓名" prop="staffName">
        <el-input
          v-model="queryParams.staffName"
          placeholder="请输入姓名"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--ToDo 少组别信息-->
      <el-form-item label="组别" prop="zubie">
        <el-input
          v-model="queryParams.zubie"
          placeholder="请输入组别"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row>
        <el-button
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['termJob:attendanceDay:detail:export']"
        >导出
        </el-button>
    </el-row>
    <el-table
      :data="tableData"
      v-loading="loading"
      style="width:100%;margin-top:10px"
      highlight-current-row
      @current-change="handleCurrentChange"
    >
      <el-table-column label="id" prop="id" v-if="false"/>
      <el-table-column
        label="序号"
        type="index"
        width="80"
      ></el-table-column>
      <el-table-column label="姓名" prop="staffName" min-width="100"/>
      <el-table-column label="身份证" prop="idCard" min-width="180"/>
      <!--todo-->
      <el-table-column label="组别" prop="zubie" min-width="100"/>
      <el-table-column label="岗位" prop="postName" min-width="100"/>

      <el-table-column label="通班" prop="allDaySignTime" min-width="60"/>
      <el-table-column label="白班" prop="daySignTime" min-width="60"/>
      <el-table-column label="夜班" prop="nightSignTime" min-width="60"/>

      <el-table-column label="应出勤天数" prop="needSign" min-width="100"/>
      <!--todo-->
      <el-table-column label="休息天数" prop="numberOfRest" min-width="100"/>
      <el-table-column label="实际出勤天数" prop="actualSign" min-width="100"/>

      <el-table-column label="普通迟到次数" prop="normallyLate" min-width="100"/>
      <el-table-column label="一般迟到次数" prop="usuallyLate" min-width="100"/>
      <el-table-column label="严重迟到次数" prop="severelyLate" min-width="100"/>
      <el-table-column label="早退次数" prop="leaveEarly" min-width="100"/>
      <el-table-column label="旷工次数" prop="absenteeism" min-width="100"/>
    </el-table>
    <pagination
      v-show="total > 10"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-sizes="[10]"
      @pagination="getTableRecords"
    />
  </div>
</template>

<script>
import {listUserMonthAttendance,userMonthAttendanceExport} from "@/api/job/attendance/attendanceMonth";

export default {
  data() {
    return {
      tableData: [],
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      aid: undefined,
      // 显示搜索条件
      showSearch: true,
      total: 6,
      // 系统设定的正常应该工作的时间
      normalWorkDays: 1,
      workTime: this.$route.query.workTime,
      deptName: this.$route.query.deptName,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workTime: this.$route.query.workTime,
        deptId: this.$route.query.deptId
      },
    };
  },
  created() {
    this.getTableRecords();
  },
  methods: {

    // 搜索
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getTableRecords();
    },

    // 表单重置
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {
        workTime: this.$route.query.workTime,
        deptId: this.$route.query.deptId
      };
      this.handleQuery();
    },

    //查询接口
    getTableRecords() {
      this.loading = true;
      listUserMonthAttendance(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    handleExport() {
      this.$confirm('是否确认导出月考勤明细数据?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return userMonthAttendanceExport({workTime:this.$route.query.workTime,deptId:this.$route.query.deptId});
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    },
    //员工的考勤详情
    handleCurrentChange(val) {
      this.currentRow = val;
      this.$router.push({
        // path: "/personnel/attendance/staffAttendanceMonthDetail",
        path: "/attendance/staffAttendanceMonthDetail",
        query: {
          workTime: this.$route.query.workTime,
          deptId: this.$route.query.deptId,
          staffName: val.staffName,
          idCard: val.idCard
        }
      });
    }
  }
};
</script>


